﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VgoCardChange.Models.Objects;
using VgoCardChange.Models;

namespace VgoCardChange.Controllers
{
    public class GameController : Controller
    {
        //
        // GET: /Game/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetGames()
        {
            List<Game> listgame = new List<Game>();
            GameModels GameMd = new GameModels();
            listgame = GameMd.GetGames();
            ViewData["listgame"] = listgame;
            return View();
        }
        public ActionResult CreateGame()
        {
            return View();
        }
        [HttpPost]
        public ActionResult CreateGame(string GameName)
        {
            GameModels GameMd = new GameModels();
            Game game = new Game();
            // game.GameID = GameID;
            game.GameName = GameName;
            GameMd.CreateGame(game);
            return RedirectToAction("GetGames");
        }
        public ActionResult EditGame(int GameID)
        {
            GameModels GameMd = new GameModels();
            List<Game> listgameid = new List<Game>();
            listgameid = GameMd.GetGameID(GameID);
            ViewData["listgameid"] = listgameid;
            return View(listgameid);

        }
        [HttpPost]
        public ActionResult EditGame(int GameID, string GameName)
        {
            GameModels GameMd = new GameModels();
            Game game = new Game();
            game.GameID = GameID;
            game.GameName = GameName;
            GameMd.EditGame(game);
            return RedirectToAction("GetGames");
        }
        public ActionResult DeleteGame(int GameID)
        {
            GameModels GameMd = new GameModels();
            List<Game> listgameid = new List<Game>();
            listgameid = GameMd.GetGameID(GameID);
            ViewData["listgameid"] = listgameid;
            return View(listgameid);
 
        }
        [HttpPost]
        public ActionResult DeleteGame(int GameID, FormCollection coll)
        {

            GameModels GameMd = new GameModels();
            GameMd.DeleteGame(GameID);
            return RedirectToAction("GetGames");
        }

    }
}
